package hy.controller;

import hy.beans.Result;
import hy.beans.User;
import hy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;
    /*登录，从数据库查询是否正确，如果正确,{手机号:用户信息}写入redis的一个为key为phones的hash类型中*/
    @RequestMapping("/login")
    public Result login(User user) throws Exception {
        boolean isLogin=userService.doLogin(user);
        Result rs=new Result();
        if(isLogin){
            rs.setSuccess(true);
            rs.setStorage(user.getPhone());
        }
        return rs;
    }

    @RequestMapping("/isLogin")
    public User get(@RequestBody User u) throws Exception {
        User us=userService.get(u.getPhone());
        System.out.println(us);
        return us;
    }
}